import request from '../../utils/request';

/**
 * 获取单个组件下所有动效
 */
export function fetch(widgetId) {
  return request(`${is.CONST.urls.timelines}?widget_id=${widgetId}`);
}

/**
 * 创建单个动效
 */
export function create(timeline,widgetId) {
  return request(`${is.CONST.urls.timelines}?widget_id=${widgetId}`, {
    method: 'POST',
    body: JSON.stringify(timeline),
  });
}

/**
 * 更新单个动效
 */
export function updateOne(widgetId, timeline) {
  return request(`${is.CONST.urls.timelines}?widget_id=${widgetId}`, {
    method: 'PUT',
    body: JSON.stringify(timeline),
  });
}

/**
 * 删除单个动效
 */
export function remove(widgetId, timelineId) {
  return request(`${is.CONST.urls.timelines}?widget_id=${widgetId}&id=${timelineId}`, {
    method: 'DELETE',
  });
}

/**
 * 更新多个动效
 */
export function updateAll(widgetId, timelines) {
  return request(`${is.CONST.urls.widgetTimelines}`, {
    method: 'PUT',
    body: JSON.stringify({
      widget_id:
      timelines,
    }),
  });
}
